<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<div th:replace="pages/admin/commons/header :: header"></div>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
<body>
<div class="wap-container">
    <nav class="breadcrumb" style="background-color:#fff;padding: 0 24px">
        首页
        <span class="c-gray en">/</span>
        儿童保健
        <span class="c-gray en">/</span>
        专案儿童标准指导
        <a class="btn btn-success radius f-r" href="javascript:location.replace(location.href);"
           style="line-height:1.6em;margin-top:3px" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <article class="Hui-admin-content clearfix">
        <div class="wap-container">
            <div class="panel">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                    <legend>专案儿童标准指导</legend>

                    <a style="float: right; margin-right: 5%" href="javascript:;" id="add_record"
                       class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加数据</a>
                    <div style="width: 250px;margin-left: 35%" th:if="${result} == null"
                         class="form-controls col-xs-8 col-sm-9">
                        <span class="select-box">
							<select id="sel2" class="select" name="category">
							</select>
                        </span>
                    </div>
                </fieldset>

                <div style="display: inline-block; width: 68%; height: 410px; padding: 10px; border: 1px solid #ddd; overflow: auto;margin-left: 15%">

                    <table style="float: right;" class="layui-table">
                        <colgroup>
                            <col width="150">
                            <col width="200">
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th style="width: 15%">序号</th>
                            <th style="width: 60%">保健指导内容</th>
                            <th style="width: 25%">操作</th>
                        </tr>
                        </thead>
                        <tbody id="nodeInfo">

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!--				<td class="va-t"><iframe ID="testIframe" Name="testIframe" FRAMEBORDER=0 SCROLLING=AUTO width=100%  height=390px SRC="product-category-add.html"></iframe></td>-->
    </article>
</div>
<!--_footer 作为公共模版分离出去-->
<div th:replace="pages/admin/commons/footer :: footer"></div>
<script th:src="@{/layui/layui.js}" charset="utf-8"></script>
<script type="text/javascript">

    $(function () {

        var add_record_node = '';
        $.ajax({
            url: "/childhealth/childrenStandard/getChildrenStandardParent",
            method: "POST",
            success: function (result) {
                $.each(result.data, function (index, item) {
                    var op1 = $("<option value='" + item.id + "'></option>").append(item.information);
                    $("#sel2").append(op1);
                })
                var x = $($("#sel2").find("option").get(0)).val();
                add_record_node = x;
                getDetail(x);

            }
        })

        $("#sel2").change(function () {
            add_record_node = $(this).val();
            getDetail($(this).val());
        })

        function getDetail(id) {
            $.ajax({
                url: "/childhealth/childrenStandard/getChildrenStandardDetail/" + id,
                method: "POST",
                success: function (result) {
                    $('#nodeInfo').empty();
                    var node = result.data;
                    $.each(node, function (index, item) {
                        var tdCode = $("<td></td>").append(item.orderNumber);
                        var tdDetail = $("<td></td>").append(item.detail);
                        var tdOther = $("<td></td>").append(
                            "<button uniqueId=" + item.id + " class=\"btn btn-danger radius delBtn\" type=\"button\"><i class=\"Hui-iconfont\"></i > 删除 </button>" +
                            "&nbsp;&nbsp;" +
                            "<button uniqueId=" + item.id + " class=\"btn btn-success radius updBtn\" type=\"button\"><i class=\"Hui-iconfont\"></i > 修改 </button>");
                        $("<tr></tr>").append(tdCode).append(tdDetail).append(tdOther).appendTo("#nodeInfo");
                    });


                    //删除
                    $(".delBtn").on('click', function () {
                        var uniqueId = $(this).attr("uniqueId");
                        layer.confirm('是否确定删除: ' + $(this).parent().parent().find('td').eq(1).text() + ' ？', {
                            btn: ['删除', '取消'] //按钮
                        }, function () {
                            layer.msg('删除成功！', {icon: 1});
                            setInterval(function () {
                                window.location.href = "/childhealth/childrenStandard/data-del?id=" + uniqueId;
                            }, 1000)
                        });


                    })

                    //修改
                    $(".updBtn").on('click', function () {
                        member_add('修改', '/childhealth/childrenStandard/data-upd?type=toUpd&nodeId=' + $(this).attr("uniqueId"), '', '510')
                    })
                }
            })
        }

        /*
        *
        *  layui.use('tree', function () {
                    var tree = layui.tree;
                    //渲染
                    var inst1 = tree.render({
                        elem: '#demo1',  //绑定元素
                        data: result.data,
                        click: function (obj) {
                            if (obj.data.children == undefined) {
                                //添加记录的父类id
                                add_record_node = obj.data.id;
                                $.ajax({
                                    url: "/childhealth//getNodeInfo/" + obj.data.id,
                                    method: "post",
                                    success: function (result) {
                                        $('#nodeInfo').empty();

                                        if (result.data == "") {
                                            $("<tr></tr>").append($("<td style='text-align:center' colspan=\"4\"></td>").append("数据为空!")).appendTo("#nodeInfo")

                                        }
                                        console.log(result);
                                        var node = result.data;
                                        $.each(node, function (index, item) {
                                            var tdCode = $("<td></td>").append(item.orderNumber);
                                            var tdDetail = $("<td></td>").append(item.detail);
                                            var tdOther = $("<td></td>").append(
                                                "<button uniqueId=" + item.id + " class=\"btn btn-danger radius delBtn\" type=\"button\"><i class=\"Hui-iconfont\"></i > 删除 </button>" +
                                                "&nbsp;&nbsp;" +
                                                "<button uniqueId=" + item.id + " class=\"btn btn-success radius updBtn\" type=\"button\"><i class=\"Hui-iconfont\"></i > 修改 </button>");
                                            $("<tr></tr>").append(tdCode).append(tdDetail).append(tdOther).appendTo("#nodeInfo");
                                        });


                                        //删除
                                        $(".delBtn").on('click', function () {
                                            var uniqueId = $(this).attr("uniqueId");
                                            // if (confirm('是否确定删除:' + $(this).parent().parent().find('td').eq(1).text())) {
                                            //
                                            //     window.location.href = "/childhealth/dataDictionary/data-del?id=" + $(this).attr("uniqueId");
                                            // }
                                            layer.confirm('是否确定删除: ' + $(this).parent().parent().find('td').eq(1).text() + ' ？', {
                                                btn: ['删除', '取消'] //按钮
                                            }, function () {
                                                layer.msg('删除成功！', {icon: 1});
                                                setInterval(function () {
                                                    window.location.href = "/childhealth//data-del?id=" + uniqueId;
                                                }, 1000)
                                            });


                                        })


                                        //修改
                                        $(".updBtn").on('click', function () {
                                            member_add('修改', '/childhealth//data-upd?type=toUpd&nodeId=' + $(this).attr("uniqueId"), '', '510')
                                            // window.location.href =;
                                        })
                                        // console.log(result);
                                    }
                                })

                            } else {
                                add_record_node = '';
                            }
                            // console.log(obj.data); //得到当前点击的节点数据
                            // console.log(obj.state); //得到当前节点的展开状态：open、close、normal
                            // console.log(obj.elem); //得到当前节点元素
                            // console.log(obj.data.children); //当前节点下是否有子节点
                        }
                    });
                });
        * */

        //添加记录
        $("#add_record").click(function () {
            member_add('添加', '/childhealth/childrenStandard/data-upd?type=toAdd&addRecordNode=' +
                add_record_node, '', '510'
            )
        })
    })

</script>
</body>
</html>
